home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / pdcurs21 / portable / subwin.c < prev    next >
C/C++ Source or Header  |  1993-10-30  |  3KB  |  108 lines

  1. #include <string.h>
  2. #define    CURSES_LIBRARY    1
  3. #include <curses.h>
  4. #undef subwin
  5.  
  6. #ifdef PDCDEBUG
  7. char *rcsid_subwin = "$Header: C:\CURSES\portable\RCS\subwin.c 2.1 1993/06/18 20:21:17 MH Rel MH $";
  8. #endif
  9.  
  10.  
  11.  
  12.  
  13. /*man-start*********************************************************************
  14.  
  15.   subwin()    - create subwindow
  16.  
  17.   X/Open Description:
  18.      This routine creates a new sub-window within a window.  The
  19.      dimensions of the sub-window are nlines lines and ncols
  20.      columns.  The sub-window is at position (begin_y, begin_x) on
  21.      the screen.  This position is relative to the screen, and not
  22.      to the window orig.
  23.  
  24.      The sub-window is made in the middle of the window orig, so
  25.      that changes made to either window will affect both.  When
  26.      using this routine, it will often be necessary to call
  27.      touchwin before calling wrefresh.
  28.  
  29.   PDCurses Description:
  30.      No additional PDCurses functionality.
  31.  
  32.   X/Open Return Value:
  33.      On success the subwin function returns a pointer to the new
  34.      WINDOW structure created.  On failure the function returns a
  35.      null pointer.
  36.  
  37.   PDCurses Errors:
  38.      It is an error to pass sub-window coordinates that are out of
  39.      range or a NULL WINDOW pointer.  subwin() may also return an
  40.      error if it fails to allocate enough memory for the window
  41.      structure.
  42.  
  43.   Portability:
  44.      PDCurses    WINDOW*    subwin( WINDOW* orig, int nlines,
  45.                  int ncols, int begin_y, int begin_x );
  46.      X/Open Dec '88    WINDOW*    subwin( WINDOW* orig, int nlines,
  47.                  int ncols, int begin_y, int begin_x );
  48.      BSD Curses    WINDOW*    subwin( WINDOW* orig, int nlines,
  49.                  int ncols, int begin_y, int begin_x );
  50.      SYS V Curses    WINDOW*    subwin( WINDOW* orig, int nlines,
  51.                  int ncols, int begin_y, int begin_x );
  52.  
  53. **man-end**********************************************************************/
  54.  
  55. WINDOW*    subwin(WINDOW* orig,int nlines,int ncols,int begin_y,int begin_x)
  56. {
  57. extern    void*    (*mallc)( size_t );
  58. extern    void*    (*callc)( size_t, size_t );
  59. extern    void    (*fre)( void* );
  60.  
  61.     WINDOW*    win;
  62.     int    i;
  63.     int    j = begin_y - orig->_begy;
  64.     int    k = begin_x - orig->_begx;
  65.  
  66. #ifdef PDCDEBUG
  67.     if (trace_on) PDC_debug("subwin() - called: lines %d cols %d begy %d begx %d\n",nlines,ncols,begin_y,begin_x);
  68. #endif
  69.  
  70.     if (!orig)
  71.         return( (WINDOW *)NULL );
  72.  
  73.     /*
  74.      * make sure window fits inside the original one
  75.      */
  76.     if ((begin_y < orig->_begy) ||
  77.         (begin_x < orig->_begx) ||
  78.         (begin_y + nlines) > (orig->_begy + orig->_maxy) ||
  79.         (begin_x + ncols)  > (orig->_begx + orig->_maxx))
  80.     {
  81.         return( (WINDOW *)NULL );
  82.     }
  83.     if (!nlines)    nlines = orig->_maxy - 1 - j;
  84.     if (!ncols)    ncols  = orig->_maxx - 1 - k;
  85.     if ((win = PDC_makenew(nlines, ncols, begin_y, begin_x)) == (WINDOW *) NULL)
  86.     {
  87.         return( (WINDOW *)NULL );
  88.     }
  89.  
  90.     /*
  91.      * initialize window variables
  92.      */
  93.     win->_attrs    = orig->_attrs;
  94.     win->_leave    = orig->_leave;
  95.     win->_scroll    = orig->_scroll;
  96.     win->_nodelay    = orig->_nodelay;
  97.     win->_use_keypad    = orig->_use_keypad;
  98.     win->_parent    = orig;
  99.  
  100.     for (i = 0; i < nlines; i++)
  101.     {
  102.         win->_y[i] = (orig->_y[j++]) + k;
  103.     }
  104.  
  105.     win->_flags |= _SUBWIN;
  106.     return (win);
  107. }
  108.